<?php

namespace app\company\controller;

use app\company\validate\WarehouseTakeStockGoodsValidate;
use app\service\traits\Crud;
use app\company\model\WarehouseTakeStockGoods as WarehouseTakeStockGoodsModel;

class WarehouseTakeStockGoods extends Base
{
    private WarehouseTakeStockGoodsModel $model;

    use Crud;

    public function initialize()
    {
        parent::initialize();
        $this->model         = new WarehouseTakeStockGoodsModel();
        $this->validateClass = WarehouseTakeStockGoodsValidate::class;
        $this->withSearch    = 'id,warehouse_take_stock_id,goods_id,goods_rule_id,is_modify';
    }

    public function format($list): mixed
    {
        return $list->each(function ($item) {
            $item->goods                  = $item->goods()->field('name,no,unit')->withTrashed()->find();
            $item->spec_name              = $item->goodsRule()->withTrashed()->value('spec_name');
            $item->warehouse_storage_name = $item->warehouseStorage()->withTrashed()->value('name');
        });
    }


}